/**
 * Copyright(c) 2013 Jade Techonologies Co., Ltd.
 *
 * History:
 *   13-5-24 下午5:13 Created by dwzhang
 */
package com.jade.framework.base.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间的工具类。
 *
 * @author dwzhang
 * @version 1.0 13-5-24 下午5:13
 */
public class DatetimeUtils
{
    public static final int SECOND_PER_MINUTE = 60;
    public static final int SECOND_PER_HOUR = 3600;
    public static final int SECOND_PER_DAY = 24 * 3600;

    public static Date clearTime(Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date getDate(int year, int month, int day)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, day);
        return calendar.getTime();
    }

    public static String formatDate(Date date, String pattern)
    {
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        return df.format(date);
    }
}
